package com.hippo.core.ui.compose.mine

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.hippo.core.R
import com.hippo.core.config.AppConfig
import com.hippo.core.core.ext.paddingBody
import com.hippo.core.ui.components.TextLayout
import com.hippo.core.ui.components.TitleBar
import com.hippo.core.ui.compose.web.WebHandler
import com.hippo.core.ui.navigation.AppRoute
import com.hippo.core.ui.theme.HippoTheme
import com.hippo.core.vm.SettingVM

@Composable
fun AboutScreen(navController: NavController,vm:SettingVM = viewModel()) {

    val clipboardManager = LocalClipboardManager.current
    val context = LocalContext.current

    Column(modifier = Modifier.fillMaxSize().background(
        color = Color.White
    )) {

        TitleBar(
            title = stringResource(R.string.about_1),
            onBack = {
                navController.popBackStack()
            }
        )

        Column(
            modifier = Modifier
                .fillMaxSize()
                .paddingBody()
        ) {

            Image(
                painter = painterResource(id = R.mipmap.login_logo),
                contentDescription = "logo",
                modifier = Modifier
                    .size(100.dp)
                    .align(Alignment.CenterHorizontally)
            )

            TextLayout(text = stringResource(R.string.about_5),rightPainter = painterResource(R.mipmap.copy)){
                clipboardManager.setText(AnnotatedString( context.getString(R.string.about_5)))
            }
            val title2 = stringResource(R.string.about_2)
            TextLayout(text = title2){
                WebHandler.openWeb(navController,url = AppConfig.USER_POLICY,title = title2)
            }
            val title3 = stringResource(R.string.about_3)
            TextLayout(text = title3){
                WebHandler.openWeb(navController,url = AppConfig.PRIVACY_POLICY,title = title3)
            }
            TextLayout(text = stringResource(R.string.about_4)){
                vm.checkVersion(context)
            }



        }

    }

}


@Preview(showBackground = true)
@Composable
private fun AboutScreenPreview() {
    HippoTheme {
        AboutScreen(
            navController = rememberNavController()
        )
    }
}